<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>小说类别管理</title>
    <link rel="stylesheet" type="text/css" href="/tourismsystem/css/query.css" />
    <script type="text/javascript" src="/tourismsystem/js/jquery-3.2.1.js"></script>
    <script type="text/javascript">
        $(function (){
            var param = new URLSearchParams(window.location.search);
            var pageno = param.get("pageNo");
            var likeValue = param.get("likeValue");
            selectByPage(pageno,likeValue)

            $("#selectByLikeValue").click(function (){
                var likeValuestr = $.trim($("#likeValueStr").val());
                selectByPage(1,likeValuestr);
            })
        })

        function selectByPage(pageno,likeValue){
            var url = "/tourismsystem/selectByPage.new"
            var paramObj = {
                "pageNo" : pageno,
                "likeValue" : likeValue
            };
            $.post(url,paramObj,function (data){
                $("#tbodyList").empty();
                var jsonObj = JSON.parse(data);
                var recordList = jsonObj.recordList;
                for (let i = 0; i < recordList.length; i++) {
                    $("<tr><td>"+recordList[i].title+"</td><td>"
                        +recordList[i].createtime+"</td><td>"
                        +recordList[i].category+"</td>"
                        +"<td><a href='/tourismsystem/toEdit.new?newid=" + recordList[i].newid + "'>编辑</a></td>" +
                        "<td><a href='/tourismsystem/deleteById.new?newid=" + recordList[i].newid + "' onclick='confirmDelete(this)'>删除</a></td></tr>"
                    ).appendTo($("#tbodyList"))
                }
                $("#likeValueStr").val(jsonObj.likeValue);
                $("#recordCount").text(jsonObj.recordCount);
                $("#totalPages").text(jsonObj.totalPages);
                $("#pageNo").text(jsonObj.pageNo);

                $("#firstPage").prop("href","/tourismsystem/toList.new?pageNo=1&likevalue=")
                if (jsonObj.pageNo!=1)
                    $("#prevPage").prop("href","/tourismsystem/toList.new?pageNo=" + (jsonObj.pageNo-1) + "&likeValue=" + jsonObj.likeValue);
                if (jsonObj.pageNo!=jsonObj.totalPages)
                    $("#nextPage").prop("href","/tourismsystem/toList.new?pageNo=" + (jsonObj.pageNo+1) + "&likeValue=" + jsonObj.likeValue);
                $("#tailPage").prop("href","/tourismsystem/toList.new?pageNo=" + jsonObj.totalPages + "&likeValue=" + jsonObj.likeValue);
            })
        }
        function confirmDelete(aNode){
            var categoryName = $(aNode).parent().parent().find("td").eq(1).text();
            if (!confirm("确认删除"+categoryName+"的信息吗")){
                event.preventDefault();//阻止控件默认行为
            }
        }
    </script>
</head>
<body>
<div id="top">·当前位置： 资讯管理 -- 查看资讯</div>
<div id="contexttop">
    <table id="tab" border="1">
        <tr>
            <td colspan="6" height="50px">
                <input type="text" id="likeValueStr" title="标题" placeholder="标题" />
                <input type="button" value="查询" id="selectByLikeValue"/>
            </td>
        </tr>
        <tr bgcolor="#cccccc">
            <th>标题</th>
            <th>创建时间</th>
            <th>类别</th>
            <th colspan=2>操作</th>
        </tr>
        <tbody id="tbodyList">

        </tbody>

    </table>
</div>
<div align="center" id="contextbotton">
    &nbsp;总记录数&nbsp;<span id="recordCount"></span>&nbsp;条&nbsp;
    共&nbsp;<span id="totalPages"></span>&nbsp;页 &nbsp;
    <a id="firstPage" href="">首页</a>&nbsp;
    <a id="prevPage" href="">上一页</a> &nbsp;
    <a id="nextPage" href="">下一页</a> &nbsp;
    <a id="tailPage" href="">尾页</a>
    &nbsp;第&nbsp;<span id="pageNo"></span>&nbsp;页&nbsp;
</div>
</body>
</html>